//
//  JBWAlertView.m
//  JBWDSK
//
//  Created by 崔志伟 on 2018/8/3.
//  Copyright © 2018年 崔志伟. All rights reserved.
//

#import "JBWAlertView.h"

@interface JBWAlertLabel:UILabel

@end

@implementation JBWAlertLabel

@end

@interface JBWAlertView ()
@property (nonatomic,strong) UIView  * contentView ;
@property (nonatomic,assign) CGFloat  contentViewHight ;
@property (nonatomic,strong) UILabel  * titleLabel ;
@property (nonatomic,strong) UILabel  * conenteLabel ;

@property (nonatomic,strong) UIButton * leftBtn  ;
@property (nonatomic,strong) UIButton * rightBtn  ;
@property (nonatomic,copy) void(^leftBtnBlcok) (void) ;
@property (nonatomic,copy) void(^rightBtnBlcok) (void) ;
@end

@implementation JBWAlertView



- (UIView*)contentView{
    if (!_contentView) {
       _contentView= [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, self.contentViewHight)];
       _contentView .center = CGPointMake(JBW_SCREEN_WIDTH/2.0, JBW_SCREEN_HEIGHT/2.0);
        _contentView.backgroundColor = JBW_HEX_COLOR(0x2b2b35);
        _contentView.layer.cornerRadius = 5;
        _contentView.layer.masksToBounds = YES;
    }
    return _contentView;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 30, self.contentView.frame.size.width-30, 20)];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = [UIFont systemFontOfSize:17];
    }
    return _titleLabel;
}

- (UILabel *)conenteLabel{
    if (!_conenteLabel) {
        _conenteLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(_titleLabel.frame), self.contentView.frame.size.width-30, 60)];
        _conenteLabel.numberOfLines = 3;
        _conenteLabel.textColor = JBW_HEX_COLOR(0x50505a);
        _conenteLabel.font = [UIFont systemFontOfSize:14];
        _conenteLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _conenteLabel;
}


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self  = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
      
        
    }
    return self;
}

- (void)setContentViewHight:(CGFloat)contentViewHight{
    _contentViewHight = contentViewHight;
    [self setUpSubView];
}

- (void)setUpSubView{
    
    [self addSubview:self.contentView];
    [ self.contentView  addSubview:self.titleLabel];
    [ self.contentView  addSubview:self.conenteLabel];
    
    UIView *line =[[UIView alloc]initWithFrame:CGRectMake(0, self.contentView.frame.size.height-46, self.contentView.frame.size.width, 1)];
    line.backgroundColor = JBW_HEX_COLOR(0x50505a);
    [ self.contentView  addSubview:line];
    //
    self.leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, self.contentView.frame.size.height-45, self.contentView.frame.size.width/2.0, 45)];
    self.leftBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.leftBtn addTarget:self action:@selector(leftBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [ self.contentView  addSubview:self.leftBtn];
    //
    self.rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.contentView.frame.size.width/2.0, self.contentView.frame.size.height-45, self.contentView.frame.size.width/2.0, 45)];
    self.rightBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.rightBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self.rightBtn addTarget:self action:@selector(rightBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [ self.contentView  addSubview:self.rightBtn];
    UIView *centerLine =[[UIView alloc]initWithFrame:CGRectMake(self.contentView.frame.size.width/2.0-0.5, self.contentView.frame.size.height-46, 1, 45)];
    centerLine.backgroundColor = JBW_HEX_COLOR(0x50505a);
    [ self.contentView  addSubview:centerLine];
    
}

- (void)leftBtnAction{

    if (self.leftBtnBlcok) {
        self.leftBtnBlcok();
    }
    [self removeFromSuperview];
}

- (void)rightBtnAction{
    
    if (self.rightBtnBlcok) {
        self.rightBtnBlcok();
    }
    [self removeFromSuperview];
}

+(void)showBindingPhone:(void(^)(void))cancelBlcok suerBlcok:(void(^)(void))suerBlcok{
    
    JBWAlertView * alertView = [[JBWAlertView alloc]initWithFrame:CGRectMake(0, 0, JBW_SCREEN_WIDTH, JBW_SCREEN_HEIGHT)];
    alertView.contentViewHight = 180;
    alertView.leftBtnBlcok = cancelBlcok;
    alertView.rightBtnBlcok = suerBlcok;
    [alertView.leftBtn setTitle:@"取消" forState:UIControlStateNormal];
    [alertView.rightBtn setTitle:@"立即绑定" forState:UIControlStateNormal];
    alertView.titleLabel.text = @"未绑定手机";
    alertView.conenteLabel.text = @"未绑定手机忘记密码可以用手机找回哦";
    [JBW_KEY_WINDOW addSubview:alertView];
}

+(void)showRealNameAuthentication:(void(^)(void))cancelBlcok suerBlcok:(void(^)(void))suerBlcok{
    JBWAlertView * alertView = [[JBWAlertView alloc]initWithFrame:CGRectMake(0, 0, JBW_SCREEN_WIDTH, JBW_SCREEN_HEIGHT)];
    alertView.contentViewHight = 180;
    alertView.leftBtnBlcok =cancelBlcok;
    alertView.rightBtnBlcok =suerBlcok;
    [alertView.leftBtn setTitle:@"下次再说" forState:UIControlStateNormal];
    [alertView.rightBtn setTitle:@"立即完成" forState:UIControlStateNormal];
    alertView.conenteLabel.text = @"根据政策要求\n防沉迷系统需要你完成实名认证";
    [JBW_KEY_WINDOW addSubview:alertView];
}
+(void)showSwitchAccount:(void(^)(void))cancelBlcok suerBlcok:(void(^)(void))suerBlcok{
    
    JBWAlertView * alertView = [[JBWAlertView alloc]initWithFrame:CGRectMake(0, 0, JBW_SCREEN_WIDTH, JBW_SCREEN_HEIGHT)];
    alertView.contentViewHight = 120;
    alertView.leftBtnBlcok =cancelBlcok;
    alertView.rightBtnBlcok =suerBlcok;
    [alertView.leftBtn setTitle:@"取消" forState:UIControlStateNormal];
    [alertView.rightBtn setTitle:@"切换" forState:UIControlStateNormal];
    alertView.titleLabel.text = @"确定要切换账号";
    [JBW_KEY_WINDOW addSubview:alertView];
}



+(void)showMessage:(NSString *)message{
  
    JBWAlertLabel * contentLabel= [[JBWAlertLabel alloc]initWithFrame:CGRectMake(0, 0, 200, 80)];
    contentLabel.center = CGPointMake(JBW_SCREEN_WIDTH/2.0, JBW_SCREEN_HEIGHT/2.0);
    contentLabel.textColor = [UIColor whiteColor];
    contentLabel.numberOfLines = 3;
    contentLabel.font = [UIFont systemFontOfSize:14];
    contentLabel.textAlignment = NSTextAlignmentCenter;
    contentLabel.backgroundColor = JBW_HEX_COLOR(0x2b2b35);
    contentLabel.layer.cornerRadius = 5;
    contentLabel.layer.masksToBounds = YES;
    contentLabel.text = message;
    [JBW_KEY_WINDOW addSubview:contentLabel];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        for (UILabel *label in JBW_KEY_WINDOW.subviews) {
            if ([label isMemberOfClass: [JBWAlertLabel class]]) {
                [label removeFromSuperview];
            }
        }
    });
    
}

@end


